package com.minisoft.rxjava;

import io.reactivex.rxjava3.core.Emitter;
import io.reactivex.rxjava3.core.Observable;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

@Slf4j
public class RxJavaObserverDemo {

    /**
     *演示RxJava中的Observer模式
     */
    @Test
    public void rxJavaBaseUse() {
        //被观察者（主题）
        Observable observable = Observable.create( emitter -> {
                        emitter.onNext("apple");
                        emitter.onNext("banana");
                        emitter.onNext("pear");
                        emitter.onComplete();
                    });

        //订阅者（观察者）
        //订阅：Observable与Subscriber之间依然通过subscribe()进行关联
        observable.subscribe(s -> log.info("onNext: {}", s),s -> log.info("onError: {}", s),() -> log.info("onComplete") );
    }

}